package com.sanjiayi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sanjiayi.pojo.Follow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface FollowMapper extends BaseMapper<Follow> {
    
    /**
     * 获取用户的关注列表
     */
    @Select("SELECT * FROM follow WHERE follower_id = #{userId} ORDER BY create_time DESC")
    List<Follow> getFollowingList(@Param("userId") Integer userId);

    /**
     * 获取用户的粉丝列表
     */
    @Select("SELECT * FROM follow WHERE followed_id = #{userId} ORDER BY create_time DESC")
    List<Follow> getFollowerList(@Param("userId") Integer userId);

    /**
     * 获取用户的关注数量
     */
    @Select("SELECT COUNT(*) FROM follow WHERE follower_id = #{userId}")
    Integer getFollowingCount(@Param("userId") Integer userId);

    /**
     * 获取用户的粉丝数量
     */
    @Select("SELECT COUNT(*) FROM follow WHERE followed_id = #{userId}")
    Integer getFollowerCount(@Param("userId") Integer userId);
} 